package com.wtcrazy.config;

import com.wtcrazy.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Value;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration//别忘记加注解
public class WebConfig implements WebMvcConfigurer {
    @Value("${Files.upload.path}")
    private String fileSavePath;

//    @Override//适合于本地自定义路径【路径静态不变】
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {//静态资源映射
//        //将网页地址栏中的/Files/**映射到磁盘的某个目录下,以访问磁盘资源
//        registry.addResourceHandler("/Files/**")//你想在url请求的路径
//                .addResourceLocations("file:" + fileSavePath);//图片存放的真实路径
//    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {//配置对哪些请求进行拦截
        List<String> excludeTokenPath = new ArrayList<>();//除了注册登录,其他都拦截
        List<String> tokenPath = new ArrayList<>();
        tokenPath.add("/article/DeleteArticle");
//        registry.addInterceptor(new TokenInterceptor())
//                .addPathPatterns(tokenPath);
//                .excludePathPatterns(excludeTokenPath);
    }
}
